package com.yztc.orangeentertainment.ui.main.channalcontentfragment;

import android.content.Context;

import com.yztc.orangeentertainment.adapter.ChannelContentAdapter;
import com.yztc.orangeentertainment.bean.channalbean.InfoBean;
import com.yztc.orangeentertainment.bean.channalbean.ListBean;
import com.yztc.orangeentertainment.config.ChannalUrlConfig;
import com.yztc.orangeentertainment.config.SubscribeUrlConfig;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by My on 2016/10/5.
 */
public class ChannalContentPresenter implements ChannalContentContact.Presenter {
    private ChannalContentContact.Modle modle;
    private ChannalContentContact.View view;
    private ChannelContentAdapter adapter;

    public ChannalContentPresenter(ChannalContentContact.View view) {
        this.view = view;
        this.modle=new ChannalContentModle();
    }

    @Override
    public void getChannalContentFromNet(final Context context, int id, final int page) {
        String type=null;
        Map<String,String> map=new HashMap<>();
        if(id!=0) {
            map.put(ChannalUrlConfig.Params.ID, id + "");
            type=ChannalUrlConfig.PATH.URL_CHANNALCONTENT_TYPE;
        }else{
            type=ChannalUrlConfig.PATH.URL_CHANNALCONTENTTUIJIAN_TYPE;
        }
        map.put(ChannalUrlConfig.Params.PAGE,page+"");
        map.put(SubscribeUrlConfig.Params.TS, SubscribeUrlConfig.All_DefaultVaule.TS_VALUE);
        map.put(ChannalUrlConfig.Params.STARTTAG,ChannalUrlConfig
                .DefaultVaule.STARTTAG_VALUE);
        map.put(SubscribeUrlConfig.Params.MAC, SubscribeUrlConfig.All_DefaultVaule.MAC_VALUE);
        map.put(SubscribeUrlConfig.Params.UID, SubscribeUrlConfig.All_DefaultVaule.UID_VALUE);
        map.put(SubscribeUrlConfig.Params.PF, SubscribeUrlConfig.All_DefaultVaule.PF_VALUE);
        map.put(SubscribeUrlConfig.Params.NET, SubscribeUrlConfig.All_DefaultVaule.NET_VALUE);
        map.put(SubscribeUrlConfig.Params.ACCESSTOKEN, SubscribeUrlConfig.All_DefaultVaule.ACCESSTOKEN_VALUE);
        map.put(SubscribeUrlConfig.Params.CHANNEL, SubscribeUrlConfig.All_DefaultVaule.CHANNEL_VALUE);
        map.put(SubscribeUrlConfig.Params.VER, SubscribeUrlConfig.All_DefaultVaule.VER_VALUE);
        map.put(SubscribeUrlConfig.Params.RES, SubscribeUrlConfig.All_DefaultVaule.RES_VALUE);
        modle.getChannalContentViewPage(type,
                map, new OnLoadChannalContentViewPageListener() {

                    @Override
                    public void onSuccess(List<InfoBean> list) {
                        if(page==1) {
                            view.onChannalContentViewPageSucess(list);
                        }else{
                            onFailure("");
                        }

                    }

                    @Override
                    public void onFailure(String e) {
                        view.onChannalContentViewPageFaild(e);
                    }

                    @Override
                    public void onSuccessRV(ArrayList<ListBean> listBeen) {
                       view.setChannalContentRVSuccess(listBeen);
                    }

                    @Override
                    public void onFailureRV(String e) {

                    }
                }
        ,context);
    }

    @Override
    public void getChannalContentFromDb() {

    }
}
